function z = findstst(kstst)

global alpha betta depr sigmaC sigmaL omega ALPHA popweight N
global phi govexp
global lamda Delta1 Delta2

rstst = 1/betta-1+depr; %r from Euler at the steady state
estst = (rstst/alpha)^(1/(1-alpha))*kstst; % express total effective labor from r=F_k
for jj=2:N
ljpart(jj-1)=popweight(jj)*phi(jj)*lamda(jj-1)^(-sigmaC/sigmaL)*(phi(jj)/phi(1))^(1/sigmaL);
end
lstst=estst/(popweight(1)*phi(1)+sum(ljpart)); %express l1 using the expression for total effective labor and l2=f(lamda,l1)
for jj=2:N
    L2a(jj-1) = lamda(jj-1)^(-sigmaC/sigmaL)*(phi(jj)/phi(1))^(1/sigmaL); %last terms in (11) and f_l
end

wstst = (1-alpha)*kstst^alpha*estst^(-alpha); %w=F_e

mu = omega*lstst^(sigmaL)*(1+sum(ALPHA.*lamda.^(-sigmaC).*phi(2:N)'/phi(1).*L2a)+(Delta1+sum(Delta2.*phi(2:N)'/phi(1).*L2a))*(1+sigmaL))/(wstst*(popweight(1)*phi(1)+sum(ljpart)));  %FOC for labor

cstst = 1/(popweight(1)+sum(popweight(2:N).*lamda))*(kstst^alpha*estst^(1-alpha) - depr*kstst - govexp); %c from resource constraint

z = mu*(popweight(1)+sum(popweight(2:N).*lamda))-cstst^(-sigmaC)-sum(ALPHA.*lamda.*(lamda*cstst).^(-sigmaC))-(Delta1+sum(Delta2.*lamda))*(1-sigmaC)*cstst^(-sigmaC); %FOC for consumption
